Let’s deep dive into the inner working of Python!#
Do we really know what Python is? It’s a high-level, interpreted programming language. It’s known for being easy to read and write—kind of like writing in English, just with some indentations, special characters, and code blocks.
Wait, what do you mean by interpreted programming language?
It means the code is executed line-by-line or statement-by-statement by an interpreter, instead of being fully compiled into machine code before running.
Python was created by Guido van Rossum and first released in 1991.
It’s incredibly versatile and widely used in many fields like Web Development, Data Science, Automation, Scripting, Game Development, DevOps, and even App Development.
You write code in a .py file. The Python interpreter compiles it into bytecode. But here’s the thing: Python only creates .pyc bytecode files for imported modules, not for the top-level script you run directly. The top-level script is executed as-is because it usually runs once.
These bytecode files are mostly hidden and stored in a special folder called pycache. Python automatically creates and manages this folder, which keeps updating bytecode versions, handling creation and deletion.
The bytecode files have a .pyc extension, and their names look like this: module_name.cpython-XY.pyc, where XY is the Python version.
Because bytecode makes execution faster. If Python finds existing bytecode in the pycache folder, it skips recompiling and runs the bytecode directly. This saves time, especially for bigger programs or when you run scripts repeatedly.
Also, bytecode is platform-independent—you can run the same bytecode file on any machine with the same Python version, no matter the operating system. It’s simpler and more uniform than high-level Python code.
PVM stands for Python Virtual Machine. It’s the runtime engine that executes bytecode. The PVM translates bytecode into machine-level operations. It also handles memory management, function calls, exceptions, and more.
In simple terms, it’s the engine under the hood that runs your Python programs after the code has been compiled into bytecode.
Frozen binaries are standalone executable files that contain your Python source code, the Python interpreter, and all required libraries or modules. In other words, these are programs that can run without needing a separate Python installation on the user’s system.Everyone Has Their Strengths and Weaknesses — So Do Frozen Binaries